package com.bsj.pay.service.impl;

import com.bsj.pay.dao.BaseDao;
import com.bsj.pay.model.PayGoodsBean;
import com.bsj.pay.service.BaseService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author chhuean
 * @version 1.0
 * @date 2022/12/24
 **/
public abstract class BaseServiceImpl<TMapper extends BaseDao, TBean> implements BaseService<TBean> {
    protected static final Logger logger = LogManager.getLogger(getCurrentClassname());

    private static String getCurrentClassname() {
        StackTraceElement[] st = new Throwable().getStackTrace();
        return st[st.length - 1].getClassName();
    }

    @Autowired
    protected TMapper dao;

    @Override
    public long insert(TBean t) {
        return dao.insert(t);
    }

    @Override
    public int deleteById(Long id) {
        return dao.deleteById(id);
    }

    @Override
    public int removeById(Long id) {
        return dao.removeById(id);
    }

    @Override
    public int update(TBean t) {
        return dao.update(t);
    }

    @Override
    public TBean getById(Long id) {
        return (TBean) dao.getById(id);
    }

    @Override
    public List<TBean> queryList(TBean t) {
        return this.dao.queryList(t);
    }

    @Override
    public List<TBean> queryAll() {
        return this.dao.queryAll();
    }

    @Override
    public long count(TBean t) {
        return dao.count(t);
    }

    @Override
    public PageInfo<TBean> pageList(TBean t, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<TBean> list = this.dao.queryList(t);
        PageInfo<TBean> pageInfo = new PageInfo(list);
        return pageInfo;
    }
}
